home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / PublicDomain / Anwendungen / MSCalendar / src.lzh / Src / cal.c next >
C/C++ Source or Header  |  1991-06-07  |  26KB  |  872 lines

  1. /* MSCalendar ! A little FreeWare-Utility from Markus Stipp
  2.    (c) Copyright 1991 by Markus Stipp, All Rights reserved.
  3.  
  4.    $Revision: 1.10 $
  5.  
  6.    $Author: mstipp $
  7.    $Date: 91/06/07 13:33:36 $
  8.  
  9.    $Log:    cal.c,v $
  10.  * Revision 1.10  91/06/07  13:33:36  mstipp
  11.  *       Bug with -f fixed (seems to work now)
  12.  *       Now uses RawKeyConvert() for Keys
  13.  * 
  14.  * Revision 1.9  91/05/30  18:03:11  mstipp
  15.  *       V1.08 always switched to current date if Clockwindow was open
  16.  *
  17.  
  18. */
  19.  
  20. /*---------------------------------------------------------------------*/
  21. /* Prototypes / Structures / Variables etc.                            */
  22. /*---------------------------------------------------------------------*/
  23.  
  24. #include "cal.h"
  25.  
  26. void Today(void);
  27. void PrintClock(void);
  28. void PrintCal(int month, int year);
  29. void InitWindow(void);
  30. void DrawLine(int x1, int y1, int x2, int y2);
  31. void HandleKeys(USHORT code,USHORT qual,APTR address);
  32. void Iconify(void);
  33. void UnIconify(void);
  34. int  DOW(int day, int month, int year);
  35. void CleanUp(int error, char* Message);
  36. TM   *GetTime(void);
  37. int  atoi(char *string);
  38. int  strlen(char *string);
  39. void exit(int error);
  40. void InitMain(void);
  41. void GetVals(void);
  42. void CheckVals(void);
  43. void DoMain(void);
  44.  
  45. static IBASE   *IntuitionBase = NULL;
  46. static GFXBASE *GfxBase = NULL;
  47. struct Library *IconBase = NULL;
  48. struct ConsoleDevice *ConsoleDevice = NULL;
  49. struct IOStdReq ioreq;
  50.  
  51. CAL     cal;
  52. TM      *tp;
  53. MSGP    *timeport;
  54. TR      tr;
  55. BYTE    BHeight;
  56. UWORD   FHeight,FWidth,FWidth2,BLine,BLine2;
  57. BOOL    gadget,winactive,tdevice,current = FALSE;
  58. TF      *FontBuf;
  59. SCR     scrbuf;
  60.  
  61. #ifdef GERMAN
  62. char   *monthname[] =
  63.   {
  64.     "Januar   ","Februar  ","März     ","April    ","Mai      ",
  65.     "Juni     ","Juli     ","August   ","September","Oktober  ",
  66.     "November ","Dezember "
  67.   };
  68. #else
  69. char   *monthname[] =
  70.   {
  71.     "January  ","February ","March    ","April    ","May      ",
  72.     "June     ","July     ","August   ","September","October  ",
  73.     "November ","December "
  74.   };
  75. #endif
  76.  
  77. USHORT daytab[] =
  78.   {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  79.  
  80.  
  81. /*---------------------------------------------------------------------*/
  82. /* The main Programs !                                                 */
  83. /*---------------------------------------------------------------------*/
  84.  
  85. /*---------------------------------------------------------------------*/
  86. /* If started from WB                                                  */
  87. /*---------------------------------------------------------------------*/
  88.  
  89. int wbmain(struct WBStartup *wbs)
  90. {
  91.  
  92. /* Variables */
  93.  
  94.  struct DiskObject *dobj;
  95.  char **toolsarray;
  96.  char *s;
  97.  int val;
  98.  BPTR olddir;
  99.  
  100.  InitMain();
  101.  
  102.  IconBase = OpenLibrary("icon.library",33);
  103.  if(IconBase == NULL)
  104.     CleanUp(RETURN_FAIL,"Can't open Icon.Library");
  105.  
  106.  olddir = CurrentDir(wbs->sm_ArgList->wa_Lock);
  107.  if(dobj= (struct DiskObject *) GetDiskObject(wbs->sm_ArgList->wa_Name));
  108.  {
  109.     toolsarray = (char **)dobj->do_ToolTypes;
  110.     if(s=(char *)FindToolType(toolsarray,"FLAGS"))
  111.     {
  112.        if(MatchToolValue(s,"BEEP"))
  113.           cal.Beep = TRUE;
  114.        if(MatchToolValue(s,"FRONT"))
  115.           cal.Front = TRUE;
  116.        if(MatchToolValue(s,"ICONIFY"))
  117.           cal.Iconify = TRUE;
  118.     }
  119.     if(s=(char *)FindToolType(toolsarray,"XPOS"))
  120.     {
  121.        val = atoi(s);
  122.        cal.xpos = val;
  123.     }
  124.     if(s=(char *)FindToolType(toolsarray,"YPOS"))
  125.     {
  126.        val = atoi(s);
  127.        cal.ypos = val;
  128.     }
  129.     if(s=(char *)FindToolType(toolsarray,"IXPOS"))
  130.     {
  131.        val = atoi(s);
  132.        cal.ixpos = val;
  133.     }
  134.     if(s=(char *)FindToolType(toolsarray,"IYPOS"))
  135.     {
  136.        val = atoi(s);
  137.        cal.iypos = val;
  138.     }
  139.     FreeDiskObject(dobj);
  140.  
  141.  }
  142.  CurrentDir(olddir);
  143.  
  144.  CloseLibrary(IconBase);
  145.  
  146.  DoMain();
  147.  CleanUp(0,NULL);
  148.  
  149. } /* wbmain */
  150.  
  151. /*---------------------------------------------------------------------*/
  152. /* If started from CLI                                                 */
  153. /*---------------------------------------------------------------------*/
  154.  
  155. int main(int ac, char **av)
  156. {
  157.  
  158.  /* Variables */
  159.  
  160.  char   *ptr;
  161.  int    i;
  162.  LONG   val;
  163.  
  164.  InitMain();
  165.  
  166. /***** Parse the given arguments *****/
  167.  
  168.  for(i = 1; i < ac; ++i)
  169.  {
  170.     ptr = av[i];
  171.     val = atoi(ptr+2);
  172.     if(*ptr != '-')
  173.        goto def;
  174.  
  175.     switch (ptr[1])
  176.     {
  177.        case 'x':
  178.           cal.xpos = val;
  179.           break;
  180.        case 'y':
  181.           cal.ypos = val;
  182.           break;
  183.        case 'u':
  184.           cal.ixpos = val;
  185.           break;
  186.        case 'v':
  187.           cal.iypos = val;
  188.           break;
  189.        case 'i':
  190.           cal.Iconify = TRUE;
  191.           break;
  192.        case 'b':
  193.           cal.Beep = TRUE;
  194.           break;
  195.        case 'f':
  196.           cal.Front = TRUE;
  197.           break;
  198.        default:   def:
  199. #ifdef GERMAN
  200.           printf("\nMSCalendar V%d.%02d GERMAN, " __DATE__ "\n",RELEASE,REVISION);
  201.           printf("(c)Copyright 1991 by Markus Stipp, All Rights Reserved\n\n");
  202.           printf("  Usage: %s [-Option] [-Option] [...]\n\n",av[0]);
  203.           printf("    -x###    X-Position vom Kalender (default 0)\n");
  204.           printf("    -y###    Y-Position vom Kalender (default 0)\n");
  205.           printf("    -u###    X-Position vom kleinen Fenster (default 0)\n");
  206.           printf("    -v###    Y-Position vom kleinen Fenster (default 0)\n");
  207.           printf("    -b       Bei vollen Stunden blitzen\n");
  208.           printf("    -f       Kleines Fenster immer im Vordergrund\n");
  209.           printf("    -i       Mit kleinem Fenster starten\n\n");
  210. #else
  211.           printf("\nMSCalendar V%d.%02d, " __DATE__ "\n",RELEASE,REVISION);
  212.           printf("(c)Copyright 1991 by Markus Stipp, All Rights Reserved\n\n");
  213.           printf("  Usage: %s [-option] [-option] [...]\n\n",av[0]);
  214.           printf("    -x###    X-Position of the Calendar (default 0)\n");
  215.           printf("    -y###    Y-Position of the Calendar (default 0)\n");
  216.           printf("    -u###    X-Position of the iconified Window (default 0)\n");
  217.           printf("    -v###    Y-Position of the iconified Window (default 0)\n");
  218.           printf("    -b       Beep at full hours\n");
  219.           printf("    -f       Put the iconified window always to front\n");
  220.           printf("    -i       Start with iconified Window\n\n");
  221. #endif
  222.           CleanUp(0,NULL);
  223.           break;
  224.     } /* switch */
  225.  }    /* for    */
  226.  
  227.  DoMain();
  228.  
  229. }           /* main */
  230.  
  231. /*---------------------------------------------------------------------*/
  232. /* Open Libraries etc.                                                 */
  233. /*---------------------------------------------------------------------*/
  234.  
  235. void InitMain(void)
  236. {
  237.  
  238.  cal.Iconify = cal.Beep = cal.Front = FALSE;  /* Default for startup */
  239.  
  240. /***** Open Libraries *****/
  241.  
  242.  IntuitionBase = (IBASE *)   OpenLibrary("intuition.library",33);
  243.  GfxBase       = (GFXBASE *) OpenLibrary("graphics.library",33);
  244.    if (GfxBase == NULL || IntuitionBase == NULL)
  245.        CleanUp(RETURN_FAIL,"Can't open Graphics- or Intuition.Library");
  246.  
  247. /***** Create a MessagePort for the Timer.Device *****/
  248.  
  249.  timeport = CreatePort(NULL,0);
  250.    if(timeport == NULL)
  251.       CleanUp(RETURN_FAIL,"Can't create Port");
  252.  
  253. /***** Open the Timer.Device *****/
  254.  
  255.  if(OpenDevice("timer.device",UNIT_MICROHZ,(IOR *) &tr,0L))
  256.     CleanUp(RETURN_FAIL,"Can't open Timer.Device");
  257.   tdevice = TRUE;
  258.  
  259. /***** Open Console Device for RawKeyConvert() *****/
  260.  
  261.  if(OpenDevice("console.device",-1L,(IOR *) &ioreq,0L))
  262.     CleanUp(RETURN_FAIL,"Can't open Console.Device");
  263.  ConsoleDevice = (struct ConsoleDevice *)ioreq.io_Device;
  264.  
  265.  cal.xpos = cal.ypos = cal.ixpos = cal.iypos = 0;
  266.  
  267. } /* InitMain */
  268.  
  269. /*---------------------------------------------------------------------*/
  270. /* Get the Screen's data and set some Variables.                       */
  271. /*---------------------------------------------------------------------*/
  272.  
  273. void GetVals(void)
  274. {
  275.  Delay(10); /* If someone changes the Font, we must wait a bit */
  276.  
  277.  Forbid();
  278.  if(!(GetScreenData(&scrbuf,sizeof(SCR),WBENCHSCREEN,NULL)))
  279.     CleanUp (RETURN_FAIL,"Can't get ScreenData");
  280.  Permit();
  281.  
  282.  FontBuf = (TF *) OpenFont(scrbuf.Font);
  283.  
  284.  BHeight        = scrbuf.BarHeight+1;
  285.  FHeight        = GfxBase->DefaultFont->tf_YSize;
  286.  FWidth         = GfxBase->DefaultFont->tf_XSiz